package com.quasar.hpatient.view.adapter.render;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.ada.adapter.RenderBuiler;
import com.quasar.hpatient.R;
import com.quasar.hpatient.model.medicalmodel.LifecycleYear;
import com.quasar.hpatient.view.personal.historyRecord.MyCaseActivity_;
import com.quasar.hpatient.view.prescription.PharmacyRecordActivity_;
import com.quasar.hpatient.view.record.EventActivity_;
import com.quasar.hpatient.view.record.TestRecordActivity_;
import com.vise.log.ViseLog;

/**
 * name : lishuai
 * time : 2017/12/29
 * title:
 */

public class LifecycleRenderBuiler extends RenderBuiler<LifecycleYear.LifecycleTesmouth> implements View.OnClickListener {

    public LifecycleRenderBuiler(Context context) {
        super(context);
        this.mContext = context;
    }

    private String Patientid;  //患者ID
    private Context mContext;

    public Context getmContext() {
        return mContext;
    }

    public void setmContext(Context mContext) {
        this.mContext = mContext;
    }

    public String getPatientid() {
        return Patientid;
    }

    public void setPatientid(String patientid) {
        Patientid = patientid;
    }

    @Override
    public void render() {
        if (getContent() != null) {
            tv_time.setText(getContent().getMouthTime());
        }
        //诊断信息
        if (getContent().getLifecycleTestItem().getDiagnoseDetailsList() != null) {
            StringBuffer stringBuffer1 = new StringBuffer();
            for (int t = 0; t < getContent().getLifecycleTestItem().getDiagnoseDetailsList().size(); t++) {

                if(getContent().getLifecycleTestItem().getDiagnoseDetailsList().get(t).getRelName()!=null
                        && getContent().getLifecycleTestItem().getDiagnoseDetailsList().get(t).getRelName().length()>0 ){
                    stringBuffer1.append(getContent().getLifecycleTestItem().getDiagnoseDetailsList().get(t).getRelName() + "\t");
                }
                //诊断内容
                if(getContent().getLifecycleTestItem().getDiagnoseDetailsList().get(t).getStatus()==100){
                    stringBuffer1.append("\t诊断：\t");
                }else{
                    //建议内容
                    stringBuffer1.append("\t建议：\t");
                }

                stringBuffer1.append(getContent().getLifecycleTestItem().getDiagnoseDetailsList().get(t).getContent() + "\n");
            }
            tv_zhenduan.setText(stringBuffer1.toString());
            tv_zhenduan.setVisibility(View.VISIBLE);
            tv_zhenduan_title.setVisibility(View.VISIBLE);
        }else{
            tv_zhenduan.setText("");
            tv_zhenduan.setVisibility(View.GONE);
            tv_zhenduan_title.setVisibility(View.GONE);
        }
        //事件
        if (getContent().getLifecycleTestItem().getInspectionEventsList() != null) {
            StringBuffer stringBuffer = new StringBuffer();
            for (int t = 0; t < getContent().getLifecycleTestItem().getInspectionEventsList().size(); t++) {
                stringBuffer.append(getContent().getLifecycleTestItem().getInspectionEventsList().get(t).getEventDesc() + "\n");
            }
            tv_shijian.setText(stringBuffer.toString());
            tv_shijian.setVisibility(View.VISIBLE);
            tv_shijian_title.setVisibility(View.VISIBLE);
        }else{
            tv_shijian.setText("");
            tv_shijian.setVisibility(View.GONE);
            tv_shijian_title.setVisibility(View.GONE);
        }
        //调药记录
        if (getContent().getLifecycleTestItem().getPharmacyRecordsList() != null && getContent().getLifecycleTestItem().getPharmacyRecordsList().size() > 0) {
            StringBuffer stringBuffer3 = new StringBuffer();
            for (int t = 0; t < getContent().getLifecycleTestItem().getPharmacyRecordsList().size(); t++) {
                stringBuffer3.append(getContent().getLifecycleTestItem().getPharmacyRecordsList().get(t).getEidtMessage().replaceAll("<br/>", "\n")  + "\n");
            }
            tv_tiaoyao.setText(stringBuffer3.toString());
            tv_tiaoyao.setVisibility(View.VISIBLE);
            tv_tiaoyao_title.setVisibility(View.VISIBLE);
        }else{
            tv_tiaoyao.setText("");
            tv_tiaoyao.setVisibility(View.GONE);
            tv_tiaoyao_title.setVisibility(View.GONE);
        }

        //病历
        if (getContent().getLifecycleTestItem().getPatientCaseHistoryList() != null) {
            StringBuffer stringBuffer4 = new StringBuffer();
            for (int t = 0; t < getContent().getLifecycleTestItem().getPatientCaseHistoryList().size(); t++) {
                stringBuffer4.append(getContent().getLifecycleTestItem().getPatientCaseHistoryList().get(t).getTitle() + "\n");
            }
            tv_bingli.setText(stringBuffer4.toString());
            tv_bingli.setVisibility(View.VISIBLE);
            tv_bingli_title.setVisibility(View.VISIBLE);
        }else{
            tv_bingli.setText("");
            tv_bingli.setVisibility(View.GONE);
            tv_bingli_title.setVisibility(View.GONE);
        }
        //不适症状
        if (getContent().getLifecycleTestItem().getTroubleDetailList() != null) {
            StringBuffer stringBuffer = new StringBuffer();
            for (int t = 0; t < getContent().getLifecycleTestItem().getTroubleDetailList().size(); t++) {
                if(getContent().getLifecycleTestItem().getTroubleDetailList().get(t).getTroubleName()!=null && getContent().getLifecycleTestItem().getTroubleDetailList().get(t).getTroubleName().length()>0){
                    stringBuffer.append("标签:"+getContent().getLifecycleTestItem().getTroubleDetailList().get(t).getTroubleName() + "\n");
                }else{
                    stringBuffer.append("描述:"+getContent().getLifecycleTestItem().getTroubleDetailList().get(t).getDescription() + "\n");
                }
            }
            tv_patientshijian.setText(stringBuffer.toString());
            tv_patientshijian.setVisibility(View.VISIBLE);
            tv_patientshijian_title.setVisibility(View.VISIBLE);
        }else{
            tv_patientshijian.setText("");
            tv_patientshijian.setVisibility(View.GONE);
            tv_patientshijian_title.setVisibility(View.GONE);
        }

    }

    @Override
    protected void setUpView(View view) {
        tv_time = (TextView) view.findViewById(R.id.tv_time);
        tv_zhenduan = (TextView) view.findViewById(R.id.tv_zhenduan);
        tv_zhenduan_title = (TextView) view.findViewById(R.id.tv_zhenduan_title);
        tv_shijian = (TextView) view.findViewById(R.id.tv_shijian);
        tv_shijian_title = (TextView) view.findViewById(R.id.tv_shijian_title);
        tv_tiaoyao = (TextView) view.findViewById(R.id.tv_tiaoyao);
        tv_tiaoyao_title = (TextView) view.findViewById(R.id.tv_tiaoyao_title);
        tv_bingli = (TextView) view.findViewById(R.id.tv_bingli);
        tv_bingli_title = (TextView) view.findViewById(R.id.tv_bingli_title);
        tv_patientshijian_title = (TextView) view.findViewById(R.id.tv_patientshijian_title);
        tv_patientshijian = (TextView) view.findViewById(R.id.tv_patientshijian);
    }

    @Override
    protected void hookListeners(View view) {
        tv_zhenduan.setOnClickListener(this);
        tv_shijian.setOnClickListener(this);
        tv_tiaoyao.setOnClickListener(this);
        tv_bingli.setOnClickListener(this);
        tv_patientshijian.setOnClickListener(this);
    }

    TextView tv_time, tv_zhenduan, tv_zhenduan_title, tv_shijian, tv_shijian_title, tv_tiaoyao, tv_tiaoyao_title, tv_bingli, tv_bingli_title, tv_patientshijian_title, tv_patientshijian;

    @Override
    protected int getlayoutid() {
        return R.layout.item_lifecycle;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //跳转诊断
            case R.id.tv_zhenduan:

                //跳转到诊断列表
                TestRecordActivity_.intent(mContext).TestTime(getContent().getMouthTime()).flags(Intent.FLAG_ACTIVITY_NEW_TASK).start();
                break;
            //跳转到事件信息
            case R.id.tv_shijian:
                TestRecordActivity_.intent(mContext).TestTime(getContent().getMouthTime()).flags(Intent.FLAG_ACTIVITY_NEW_TASK).start();

                break;
            case R.id.tv_tiaoyao:
                //跳转到调药记录列表
                PharmacyRecordActivity_.intent(mContext).start();  //跳转到调药记录页面
                break;
                //患者事件
            case R.id.tv_patientshijian:
                StringBuffer timeMoth=new StringBuffer();
                timeMoth.append(getContent().getMouthTime());
                timeMoth.append(" 00:00:00");
                ViseLog.d("跳转的时间"+timeMoth.toString());
                EventActivity_.intent(mContext).TimeDate(timeMoth.toString()).start();
                break;
                //病例跳转
            case R.id.tv_bingli:
                MyCaseActivity_.intent(mContext).start();
                break;
        }
    }
}
